/*
 * Partner.java
 *
 * Created on 10 de Julho de 2011, 12:49
 *
 */

package intopo.demonstrator.partnerclassification;

import intopo.demonstrator.Event;
import util.math.Rational;
/**
 * Represents a partner.
 *
 * @author <a href="mailto:mariano.pedro@gmail.com">Pedro Mariano</a>
 *
 * @version 1.0 10 de Julho de 2011
 */
public class Partner
	implements java.lang.Comparable<Partner>
{
	final private Event behaveAcceptably;
	/**
	 * Unique identification used to stabilise sorting of partners with same probability to behave acceptably.
	 */
	final private int id;
	static public int ID_GENERATOR = 0;
	/**
	 * Construct a new partner.
	 */
	Partner (Event behaveAcceptably)
	{
		this.behaveAcceptably = behaveAcceptably.clone ();
		id = ID_GENERATOR++;
	}
	final public void setProbability (Rational probability)
	{
		
	}
	public int compareTo (Partner p)
	{
		float diff = this.behaveAcceptably.getRawProbability () - p.behaveAcceptably.getRawProbability ();
		if (diff == 0)
			return this.id - p.id;
		else if (diff < 0)
			return -1;
		else
			return 1;
	}
	/**
	 * Perform the event partner behaves acceptably and return {@code true} if it was sucessufull.
	 * 
	 * <p> We use the implementation of the Mersenne Twister pseudo-random number generator from <i>colt</i> library.  In particular we call the method {@code nextInt()} which returns 32-bit numbers.  We compare the result with a 32 bit number.
	 *
	 * <p> The user sees the probability of this event as a rational number.
	 */
	public boolean eventBehaveAcceptably ()
	{
		return this.behaveAcceptably.eventSucess (Cache.supply);
	}
	public Rational getBehaveAcceptablyProbability ()
	{
		return this.behaveAcceptably.getProbability ();
	}
	public int getId ()
	{
		return this.id;
	}
	public String toString ()
	{
		return String.format ("%d %s", this.id, this.behaveAcceptably.getProbability ().toString ());
	}
}

// Local Variables:
// mode: java
// mode: flyspell-prog
// ispell-local-dictionary: "british"
// End:
